/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iss.examsys.rest;

import com.iss.examsys.entity.StudentExamStatus;
import com.iss.examsys.entity.User;
import org.primefaces.push.RemoteEndpoint;
import org.primefaces.push.annotation.OnClose;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.OnOpen;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;
 
/**
 *
 * Added this resource class to return the logged in user of the exam.
 * @author Nicholas Koh
 */
@PushEndpoint("/invigilate")
public class InvigilateStudentResource {

    @OnOpen
    public void onOpen(RemoteEndpoint re){
        System.out.println(">> connected: " + re.address());
    }
    
    @OnClose
    public void onClose(RemoteEndpoint re){
        System.out.println(">> disconnected: " + re.address());
    }
    
    @OnMessage(encoders = {JSONEncoder.class})
    public StudentExamStatus onMessage(StudentExamStatus status) {
        System.out.print("Add status "+status.getUserId());
        return status;
    }
    
    @OnMessage(encoders = {JSONEncoder.class})
    public Integer onMessage(Integer counter) {
        return counter;
    }
    
    @OnMessage(encoders = {JSONEncoder.class})
    public Boolean onMessage(Boolean completed) {
        return completed;
    }
}
